package com.atguigu.service.impl;

import com.atguigu.base.BaseDao;
import com.atguigu.base.BaseServiceImpl;
import com.atguigu.dao.UserFollowDao;
import com.atguigu.entity.UserFollow;
import com.atguigu.service.DictService;
import com.atguigu.service.UserFollowService;
import com.atguigu.vo.UserFollowVo;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

@DubboService
@Transactional
public class UserFollowServiceImpl extends BaseServiceImpl<UserFollow> implements UserFollowService {
    @Autowired
    private UserFollowDao userFollowDao;
    @DubboReference
    private DictService dictService;

    @Override
    protected BaseDao<UserFollow> getEntityDao() {
        return userFollowDao;
    }

    @Override
    public void follow(Long id, Long houseId) {
        UserFollow userFollow =new UserFollow();
        userFollow.setUserId(id);
        userFollow.setHouseId(houseId);
        userFollowDao.insert(userFollow);
    }

    @Override
    public boolean isFollowed(Long userId, Long houseId) {
        Integer count =userFollowDao.countByUserIdandHouseId(userId,houseId);
        return count>0;
    }

    @Override
    public PageInfo<UserFollowVo> findListPage(Integer pageNum, Integer pageSize, Long userId) {
        // 开启分页
        PageHelper.startPage(pageNum,pageSize);
        // 调用DAO的查询方法,返回page对象
        Page<UserFollowVo> page =userFollowDao.findListPage(userId);
       /* for (UserFollowVo userFollowVo : page) {
            userFollowVo.setHouseTypeName(dictService.getNameById(userFollowVo.getHouseTypeId()));
            userFollowVo.setFloorName(dictService.getNameById(userFollowVo.getFloorId()));
            userFollowVo.setDirectionName(dictService.getNameById(userFollowVo.getDirectionId()));
        }*/
        return new PageInfo<>(page,10);
    }
}
